package com.wenshi.web.socket;

import com.wenshi.system.domain.DeviceData;

import java.lang.reflect.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WebSocketMsgDeal {

    public static DeviceData dealDeviceMsg(ConcurrentHashMap<String,Integer> deviceDataMap){
        DeviceData deviceData = new DeviceData();
        Class<?> clazz = deviceData.getClass();
        for (Map.Entry<String, Integer> entry : deviceDataMap.entrySet()) {
            try {
                Field field = clazz.getDeclaredField(entry.getKey());
                field.setAccessible(true);
                Integer value = entry.getValue();
                field.set(deviceData,value.intValue());
            } catch (NoSuchFieldException | IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return deviceData;
    }
}
